const cityModel = require("@root/model/home/cityList")
const foodTypeModel = require("@root/model/home/foodType")
const restaurantModel = require("@root/model/list/restaurant")

class HomeController{

  // 获取城市列表
  async getCityList(ctx, next){
    let response = ''
    await cityModel.find((err, cityList) => {
      if(err) return console.log(
        chalk.red("find cityList error:", err)
      )
      response = JSON.stringify(cityList)
    })
    ctx.body = response
  }

  // 获取食品类别
  async getFoodType(ctx, next) {
    let response = ''
    await foodTypeModel.find((err, foodType) => {
      if(err) return console.log(
        chalk.red("find foodType error:", err)
      )
      response = JSON.stringify(foodType)
    })
    ctx.body = response
  }

  // 获取所有商家
  async getRestaurants(ctx, next) {
    let response = ''
    await restaurantModel.find((err, restaurants) => {
      if(err) return console.log(
        chalk.red("find restaurants error:", err)
      )
      response = JSON.stringify(restaurants)
    })
    ctx.body = response
  }

}

module.exports = new HomeController()